package UdpTalk;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class UdpSenderDemon1 {
    public static void main(String[] args) throws Exception {
        // 1. establish a port
        DatagramSocket socket=new DatagramSocket(8888);
        // 2. create a packet
        // get data from console
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        while(true){
            String data=br.readLine();
            byte[] datas=data.getBytes();
            DatagramPacket packet=new DatagramPacket(datas,0,datas.length,new InetSocketAddress("localhost",6666));
            // 3. send the packet
            socket.send(packet);
            if(data.equals("exit")){
                break;
            }
        }
        // 4. close
        socket.close();
    }
}
